<template>
  <div id="app">
    <h1>{{$store.getters.arr}}</h1>
    <ul>
      <li v-for="(item,index) in arr" :key="index">{{item}}</li>
    </ul>
    <h1>根组件:{{count}}</h1>
    <input type="text" :value='count' @input="change" >
    <!-- <input type="text" :value='count' @input="changeCount($event.target.value)"> -->
    <add-item></add-item>
    <hr>
    <sub-item></sub-item>
  </div>
</template>

<script>
import {mapState,mapGetters} from 'vuex'
import AddItem from './components/add-item.vue'
import SubItem from './components/sub-item.vue'
import {mapMutations} from 'vuex'

export default {
  name: 'app',
  data: function () {
    return {
      
    }
   
  },
   computed:{
      ...mapState(['count']),
        ...mapGetters(['arr'])
    },
  components: {
    AddItem,
    SubItem
  },
  methods:{
    ...mapMutations(['changeCount']),
    change(e){
       console.log(+e.target.value)
      //  this.$store.commit('changeCount',+e.target.value)
      this.changeCount(+e.target.value)
    }
  }
}
</script>

<style>
#app {
  width: 600px;
  margin: 20px auto;
  border: 3px solid #ccc;
  border-radius: 3px;
  padding: 10px;
}
</style>